<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>账户充值</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background-color: #f5f7fa;
            color: #333;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 上层样式 - 顶部导航栏 */
        .top-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 30px;
            background-color: #ffffff;
            box-shadow: 0 2px 10px rgba(0,0,0,0.08);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .back-btn {
            background-color: transparent;
            color: #4a6cf7;
            border: none;
            padding: 10px 15px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 16px;
        }

        .back-btn:hover {
            color: #3a5ce0;
            transform: translateX(-3px);
        }

        .page-title {
            font-size: 22px;
            font-weight: 700;
            color: #2c3e50;
        }

        .user-name {
            font-weight: 600;
            color: #4a6cf7;
            padding: 5px 15px;
            border-radius: 20px;
            background-color: #f0f4f8;
        }

        /* 充值区域样式 */
        .recharge-container {
            flex: 1;
            max-width: 500px;
            width: 100%;
            margin: 50px auto;
            padding: 30px;
            background-color: #ffffff;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.08);
        }

        .recharge-header {
            text-align: center;
            margin-bottom: 40px;
        }

        .recharge-header h2 {
            font-size: 28px;
            color: #2c3e50;
            margin-bottom: 10px;
        }

        .recharge-header p {
            color: #7a7e8c;
            font-size: 16px;
        }

        .form-group {
            margin-bottom: 30px;
        }

        .form-label {
            display: block;
            margin-bottom: 12px;
            font-weight: 600;
            color: #4a6cf7;
            font-size: 16px;
        }

        .amount-input {
            width: 100%;
            padding: 18px 20px;
            border: 2px solid #e1e8f0;
            border-radius: 12px;
            font-size: 20px;
            font-weight: 600;
            color: #2c3e50;
            transition: all 0.3s ease;
            text-align: center;
        }

        .amount-input:focus {
            border-color: #4a6cf7;
            box-shadow: 0 5px 15px rgba(74, 108, 247, 0.2);
            outline: none;
        }

        .amount-input::placeholder {
            color: #cbd5e0;
            font-weight: normal;
        }

        .currency-symbol {
            position: absolute;
            left: 20px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 24px;
            color: #4a6cf7;
            font-weight: bold;
        }

        .input-container {
            position: relative;
        }

        /* 支付方式 */
        .payment-methods {
            display: flex;
            gap: 15px;
            margin-bottom: 30px;
        }

        .payment-option {
            flex: 1;
            border: 2px solid #e1e8f0;
            border-radius: 12px;
            padding: 20px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease;
            background-color: #f8fafc;
        }

        .payment-option.active {
            border-color: #4a6cf7;
            background-color: #f0f7ff;
            box-shadow: 0 5px 15px rgba(74, 108, 247, 0.15);
        }

        .payment-icon {
            font-size: 36px;
            margin-bottom: 15px;
        }

        .alipay .payment-icon {
            color: #1677ff;
        }

        .wechat .payment-icon {
            color: #07c160;
        }

        .payment-name {
            font-weight: 600;
            color: #2c3e50;
        }

        /* 充值按钮 */
        .recharge-btn {
            width: 100%;
            padding: 18px;
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            color: white;
            border: none;
            border-radius: 12px;
            font-size: 18px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 8px 20px rgba(37, 117, 252, 0.3);
        }

        .recharge-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 12px 25px rgba(37, 117, 252, 0.4);
        }

        /* 推荐金额 */
        .amount-suggestions {
            display: flex;
            flex-wrap: wrap;
            gap: 12px;
            margin-top: 15px;
        }

        .amount-btn {
            flex: 1;
            min-width: 80px;
            padding: 12px;
            background-color: #f0f4f8;
            border: none;
            border-radius: 8px;
            font-weight: 600;
            color: #4a6cf7;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .amount-btn:hover {
            background-color: #e1e8f0;
            transform: translateY(-2px);
        }

        /* 弹窗样式 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.6);
            z-index: 1000;
            align-items: center;
            justify-content: center;
        }

        .modal-content {
            background-color: white;
            border-radius: 20px;
            width: 90%;
            max-width: 400px;
            padding: 40px 30px;
            text-align: center;
            box-shadow: 0 20px 50px rgba(0,0,0,0.3);
            animation: modalAppear 0.4s ease-out;
        }

        @keyframes modalAppear {
            from { opacity: 0; transform: translateY(-30px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .success-icon {
            font-size: 60px;
            color: #25d366;
            margin-bottom: 20px;
        }

        .modal h3 {
            font-size: 24px;
            color: #2c3e50;
            margin-bottom: 15px;
        }

        .modal p {
            color: #7a7e8c;
            margin-bottom: 30px;
            line-height: 1.6;
        }

        .confirm-btn {
            padding: 14px 30px;
            background-color: #4a6cf7;
            color: white;
            border: none;
            border-radius: 10px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .confirm-btn:hover {
            background-color: #3a5ce0;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(74, 108, 247, 0.3);
        }
    </style>
</head>
<body>
<!-- 上层：顶部导航栏 -->
<div class="top-bar">
    <button class="back-btn" onclick="location.href='/clients/clientuserspace'">
        <i class="fas fa-arrow-left"></i> 返回
    </button>
    <div class="page-title">账户充值</div>
    <div class="user-name" th:text="${user.username}">用户名</div>
</div>

<!-- 下层：充值区域 -->
<div class="recharge-container">
    <form id="rechargeForm" th:action="@{/clients/clientrecharge}" method="post">
        <div class="recharge-header">
            <h2>账户充值</h2>
            <p>请填写充值金额并选择支付方式</p>
        </div>

        <!-- 金额输入 -->
        <div class="form-group">
            <label class="form-label">充值金额 (元)</label>
            <div class="input-container">
                <span class="currency-symbol">¥</span>
                <!-- 数据接口：充值金额 -->
                <input type="number"
                       class="amount-input"
                       name="amount"
                       placeholder="请输入充值金额"
                       min="1"
                       max="10000"
                       step="1"
                       required>
            </div>
            <!-- 推荐金额 -->
            <div class="amount-suggestions">
                <button type="button" class="amount-btn" onclick="setAmount(50)">50元</button>
                <button type="button" class="amount-btn" onclick="setAmount(100)">100元</button>
                <button type="button" class="amount-btn" onclick="setAmount(200)">200元</button>
            </div>
        </div>
        <!-- 支付方式 -->
        <div class="form-group">
            <label class="form-label">选择支付方式</label>
            <div class="payment-methods">

                <div class="payment-option alipay active" id="alipayOption" onclick="selectPayment('alipay')">
                    <div class="payment-icon">
                        <i class="fab fa-alipay"></i>
                    </div>
                    <div class="payment-name">支付宝</div>
                    <input type="radio" name="paymentMethod" value="alipay" checked hidden>
                </div>
                <div class="payment-option wechat" id="wechatOption" onclick="selectPayment('wechat')">
                    <div class="payment-icon">
                        <i class="fab fa-weixin"></i>
                    </div>
                    <div class="payment-name">微信支付</div>
                    <input type="radio" name="paymentMethod" value="wechat" hidden>
                </div>
            </div>
        </div>

        <!-- 确认充值按钮 -->
        <button type="button" class="recharge-btn" onclick="submitRecharge()">
            <i class="fas fa-bolt"></i> 确认充值
        </button>

    </form>
</div>

<!-- 支付成功弹窗 -->
<div class="modal" id="successModal">
    <div class="modal-content">
        <div class="success-icon">
            <i class="fas fa-check-circle"></i>
        </div>
        <h3>支付成功！</h3>
        <p>您的账户已成功充值 <span id="rechargedAmount">¥0.00</span> 元</p>
        <button class="confirm-btn" onclick="redirectToHome()">确认</button>
    </div>
</div>

<!-- ... 已有代码 ... -->
<script>
    // 设置充值金额
    function setAmount(amount) {
        document.querySelector('.amount-input').value = amount;
    }

    // 选择支付方式
    function selectPayment(method) {
        document.querySelectorAll('.payment-option').forEach(option => {
            option.classList.remove('active');
        });

        document.getElementById(method + 'Option').classList.add('active');
        document.querySelector(`input[value="${method}"]`).checked = true;
    }

    // 提交充值
    function submitRecharge() {
        const amountInput = document.querySelector('.amount-input');
        const amount = amountInput.value;

        // 验证金额
        if (!amount || amount <= 0) {
            alert('请输入有效的充值金额');
            amountInput.focus();
            return;
        }

        // 显示充值金额
        document.getElementById('rechargedAmount').textContent = '¥' + parseFloat(amount).toFixed(2);

        // 显示成功弹窗
        document.getElementById('successModal').style.display = 'flex';

        // 提交表单
        document.getElementById('rechargeForm').submit();
    }

    // 跳转到用户主页
    function redirectToHome() {
        // 数据接口：跳转URL
        location.href = '/clients/clientuserspace'; // 实际使用时应替换为后端提供的URL
    }

    // 初始化页面
    document.addEventListener('DOMContentLoaded', function() {
        // 设置默认金额
        setAmount(100);
    });
</script>
</body>
</html>